/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.common.b;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.Set;

public class b {
    private final LinkedHashMap a;
    private int b;
    private int c;
    private int d;
    private int e;
    private int f;
    private int g;
    private int h;

    public b(int paramInt) {
        if (paramInt <= 0)
            throw new IllegalArgumentException("maxSize <= 0");
        this.c = paramInt;
        this.a = new LinkedHashMap(0, 0.75F, true);
    }

    public final Object a(Object paramObject)
  {
    if (paramObject == null)
      throw new NullPointerException("key == null");
    Object localObject1;
    synchronized (this)
    {
      localObject1 = this.a.get(paramObject);
      if (localObject1 != null)
      {
        this.g += 1;
        return localObject1;
      }
      this.h += 1;
    }
    ??? = b(paramObject);
    if (??? == null)
      return null;
    synchronized (this)
    {
      this.e += 1;
      localObject1 = this.a.put(paramObject, ???);
      if (localObject1 != null)
        this.a.put(paramObject, localObject1);
      else
        this.b += c(paramObject, ???);
    }
    if (localObject1 != null)
    {
      a(false, paramObject, ???, localObject1);
      return localObject1;
    }
    a(this.c);
    return ???;
  }

    public final Object a(Object paramObject1, Object paramObject2) {
        if ((paramObject1 == null) || (paramObject2 == null))
            throw new NullPointerException("key == null || value == null");
        Object localObject1;
        synchronized (this) {
            this.d += 1;
            this.b += c(paramObject1, paramObject2);
            localObject1 = this.a.put(paramObject1, paramObject2);
            if (localObject1 != null)
                this.b -= c(paramObject1, localObject1);
        }
        if (localObject1 != null)
            a(false, paramObject1, localObject1, paramObject2);
        a(this.c);
        return localObject1;
    }

    private void a(int paramInt) {
        while (true) {
            Object localObject1;
            Object localObject2;
            synchronized (this) {
                if ((this.b < 0) || ((this.a.isEmpty()) && (this.b != 0)))
                    throw new IllegalStateException(super.getClass().getName()
                            + ".sizeOf() is reporting inconsistent results!");
                if (this.b <= paramInt)
                    return;
                Object localObject3 = null;
                Iterator localIterator = this.a.entrySet().iterator();
                while (localIterator.hasNext()) {
                    Map.Entry localEntry = (Map.Entry) localIterator.next();
                    localObject3 = localEntry;
                }
                if (localObject3 == null)
                    return;
                localObject1 = localObject3.getKey();
                localObject2 = localObject3.getValue();
                this.a.remove(localObject1);
                this.b -= c(localObject1, localObject2);
                this.f += 1;
            }
            a(true, localObject1, localObject2, null);
        }
    }

    protected void a(boolean paramBoolean, Object paramObject1, Object paramObject2, Object paramObject3) {}

    protected Object b(Object paramObject) {
        return null;
    }

    private int c(Object paramObject1, Object paramObject2) {
        int i = b(paramObject1, paramObject2);
        if (i < 0)
            throw new IllegalStateException("Negative size: " + paramObject1 + "=" + paramObject2);
        return i;
    }

    protected int b(Object paramObject1, Object paramObject2) {
        return 1;
    }

    public final synchronized String toString() {
        int i = this.g + this.h;
        int j = (i != 0) ? 100 * this.g / i : 0;
        return String.format(
                "LruCache[maxSize=%d,hits=%d,misses=%d,hitRate=%d%%]",
                new Object[] { Integer.valueOf(this.c), Integer.valueOf(this.g), Integer.valueOf(this.h),
                        Integer.valueOf(j) });
    }
}